package com.pll.mapper;

import com.pll.controller.Merchant.vo.MerchantAuthenticationVo;
import com.pll.pojo.Merchant;
import com.pll.pojo.MerchantCheck;
import org.apache.ibatis.annotations.*;

import java.util.Map;

@Mapper
public interface MerchantMapper
{
    @Select("SELECT * FROM merchant WHERE account=#{account}")
    Merchant getMerchantStatus(String account);


    @Update("UPDATE merchant set " +
            "mer_name=#{merchantAuthenticationVo.shopName}," +
            "mer_phone=#{merchantAuthenticationVo.contactPhone}," +
            "mer_address=#{merchantAuthenticationMap.address}," +
            "address_longitude=#{merchantAuthenticationMap.longitude}," +
            "address_latitude=#{merchantAuthenticationMap.latitude}," +
            "business_time=#{merchantAuthenticationMap.businessTime}," +
            "type_id=#{merchantAuthenticationVo.shopCategory}," +
            "legaler_name=#{merchantAuthenticationMap.name}," +
            "legaler_identify=#{merchantAuthenticationMap.idNumber}," +
            "legaler_identify_url=#{merchantAuthenticationMap.idCardFrontOssUrl}," +
            "license=#{merchantAuthenticationMap.regNum}," +
            "license_url=#{merchantAuthenticationMap.businessLicenseOssUrl}," +
            "certification=1 WHERE account=#{merchantAuthenticationVo.account}")
    Integer merchantAuthentication(@Param("merchantAuthenticationVo") MerchantAuthenticationVo merchantAuthenticationVo,
                                   @Param("merchantAuthenticationMap") Map<String, Object> merchantAuthenticationMap);

    @Insert("INSERT INTO merchant_check(check_mer_id) VALUES (#{merchantId})")
    Integer addCheck(Integer merchantId);

    @Select("SELECT mer_id FROM merchant WHERE account=#{account}")
    Integer queryMerchantId(String account);

    @Select("SELECT * FROM merchant_check WHERE check_mer_id = #{merId}")
    MerchantCheck getCheckResult(Integer merId);

    @Select("SELECT * FROM merchant_check WHERE check_mer_id = #{merchantId}")
    Integer getCheckExist(Integer merchantId);

    @Update("UPDATE merchant_check SET check_result = 0 WHERE check_mer_id=#{merchantId}")
    Integer updateCheckResult(Integer merchantId);
}
